#!/bin/bash

source ../cluster_IP.conf || exit -1

cluster_id=0
# kafka config
KAFKA_PORT="9092"
KAFKA_IP="192.168.1.101"
KAFKA_TOPIC="ceph"

./install-deps.sh
ARGS="-DCMAKE_BUILD_TYPE=RelWithDebInfo -DWITH_MANPAGE=OFF -DWITH_BABELTRACE=OFF -DWITH_MGR_DASHBOARD_FRONTEND=OFF" ./do_cmake.sh
cd build
make -j16
sudo make install -j16

# start virtual ceph cluster
../src/stop.sh
rm -rf out dev
# MON=1 MDS=1 MGR=1 ../src/vstart.sh --smallmds --new -X --localhost --msgr1 --without-dashboard -c 0 --fabric_kafka_brokers "192.168.1.101:9092" --fabric_kafka_topic ceph --fabric_sdk_addr "192.168.1.101:8080" --size_of_object_put_to_fabric 4194304
MON=1 MDS=1 MGR=1 ../src/vstart.sh  --smallmds --new -X --localhost --msgr1 --without-dashboard -c 0 --fabric_kafka_brokers "192.168.1.101:9092" --fabric_kafka_topic ceph --fabric_sdk_addr "192.168.1.101:8080" --size_of_object_put_to_fabric 4096
ceph config set global mon_warn_on_pool_no_redundancy false
ceph -s

ceph osd pool create testbench 32 32

# test 4MB obj with put-hash-to-fabric
rados bench -p testbench 60 write -t 1 --put-hash-to-fabric --no-cleanup > ~/ssd/build-ceph/ceph-demo/testResult/test_write_4m_with_fabric.res
rados bench -p testbench 40 seq -t 32 --put-hash-to-fabric --no-cleanup > ~/ssd/build-ceph/ceph-demo/testResult/test_seq_read_4m_with_fabric.res
rados bench -p testbench 40 rand -t 32 --put-hash-to-fabric --no-cleanup > ~/ssd/build-ceph/ceph-demo/testResult/test_rand_read_4m_with_fabric.res

# test 4MB obj without put-hash-to-fabric
rados bench -p testbench 40 write -t 32 --no-cleanup > ~/ssd/build-ceph/ceph-demo/testResult/test_write_4m_without_fabric.res
rados bench -p testbench 40 seq -t 32 --no-cleanup > ~/ssd/build-ceph/ceph-demo/testResult/test_seq_read_4m_without_fabric.res
rados bench -p testbench 40 rand -t 32 --no-cleanup > ~/ssd/build-ceph/ceph-demo/testResult/test_rand_read_4m_without_fabric.res

# test 4KB obj with put-hash-to-fabric
rados bench -p testbench 40 write -t 32 -b 4096 --put-hash-to-fabric --no-cleanup > ~/ssd/build-ceph/ceph-demo/testResult/test_write_4k_with_fabric.res
rados bench -p testbench 40 seq -t 32 -b 4096 --put-hash-to-fabric --no-cleanup > ~/ssd/build-ceph/ceph-demo/testResult/test_seq_read_4k_with_fabric.res
rados bench -p testbench 40 rand -t 32 -b 4096 --put-hash-to-fabric --no-cleanup > ~/ssd/build-ceph/ceph-demo/testResult/test_rand_read_4k_with_fabric.res

# test 4KB obj without put-hash-to-fabric
rados bench -p testbench 40 write -t 32 -b 4096 --no-cleanup > ~/ssd/build-ceph/ceph-demo/testResult/test_write_4k_without_fabric.res
rados bench -p testbench 40 seq -t 32 -b 4096 --no-cleanup > ~/ssd/build-ceph/ceph-demo/testResult/test_seq_read_4k_without_fabric.res
rados bench -p testbench 40 rand -t 32 -b 4096 --no-cleanup > ~/ssd/build-ceph/ceph-demo/testResult/test_rand_read_4k_without_fabric.res

rados lspools
rados -p testbench ls

rados -p testbench cleanup

# fio
# 4MB obj
fio -directory=/home/czy/ssd/fio_test -direct=1 -iodepth 16 -thread -rw=randwrite -ioengine=libaio -bs=4M -size=1G -numjobs=32 -runtime=40 -group_reporting -name=4M_write_with_fabric
